use ggez::{glam::Vec2, Context, graphics::{self, Rect}};

use crate::particle;

pub struct PSquare {
    particle: particle::Particle,
}

impl PSquare {
    pub fn new(location: Vec2) -> PSquare {
        let particle = particle::Particle::new(location);
        PSquare { particle }
    }
}

impl particle::ParticleLike for PSquare {
    fn is_dead(&self) -> bool {
        self.particle.is_dead()
    }

    fn get_mass(&self) -> f32 {
        self.particle.get_mass()
    }

    fn apply_force(&mut self, force: Vec2) -> () {
        self.particle.apply_force(force)
    }

    fn update(&mut self) -> () {
        self.particle.size += 0.2;
        self.particle.update()
    }
    fn display(&self, ctx: &mut Context, canvas : &mut graphics::Canvas) -> () {

        let square = graphics::Mesh::new_rectangle(
            ctx, 
            graphics::DrawMode::fill(), 
            Rect::new(-self.particle.size/2.0, -self.particle.size/2.0, self.particle.size, self.particle.size), 
            graphics::Color::new(0.7, 0.7, 0.7, self.particle.lifespan)).unwrap();
        canvas.draw(&square, graphics::DrawParam::default().dest(self.particle.location).rotation(self.particle.angle)); 
    
        let square = graphics::Mesh::new_rectangle(
            ctx, 
            graphics::DrawMode::stroke(2.0), 
            Rect::new(-self.particle.size/2.0, -self.particle.size/2.0, self.particle.size, self.particle.size), 
            graphics::Color::new(0.0, 0.0, 0.0, self.particle.lifespan)).unwrap();
        canvas.draw(&square, graphics::DrawParam::default().dest(self.particle.location).rotation(self.particle.angle)); 
    }
}